﻿

function correctPNG()
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters)) 
    {
       for(var j=0; j<document.images.length; j++)
       {
          var img = document.images[j]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML
             j = j-1
          }
       }
    }    
}
window.attachEvent("onload", correctPNG);
function checkUserName(){
	var userName=document.getElementById("user_name").value;
	if(userName==""){
		document.getElementById("uname").innerHTML="用户名不能为空 ！";
		document.getElementById("uname").className="register_prompt_error";
		return false;
	}
	var yonghuming=/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
	if(yonghuming.test(userName)==false)
	{
			document.getElementById("uname").innerHTML = "字母开头5-16个字节允许字母数字下划线";
			document.getElementById("uname").className="register_prompt_error";
		return false;		
	}
	ss();

}

	function ss(){
	var a=$("#user_name").val()
	
	$.post("registdoregister.action", { "name": a },
   function(data){
		var msg=data.toString();
     if(msg=="n"){
    	document.getElementById("uname").innerHTML = "此用户名已被注册！";
		document.getElementById("uname").className="register_prompt_error";
		return false;
     }
    	document.getElementById("uname").innerHTML="通过!";
		document.getElementById("uname").className="register_prompt_ok";
		return true;
     
   });
	
}

function checkNickName(){
	var nickName=document.getElementById("nickName").value;
	if(nickName==""){
		document.getElementById("nickNamediv").innerHTML="真实名不能为空!";
		document.getElementById("nickNamediv").className="register_prompt_error";
		return false;
	}
		document.getElementById("nickNamediv").innerHTML="真实名通过!";
		document.getElementById("nickNamediv").className="register_prompt_ok";
		return true;
	
}
function checkPwd1(){
	var userName1=document.getElementById("password").value;
	if(userName1==""){
		document.getElementById("password_span").innerHTML="密码不能为空!";
		document.getElementById("password_span").className="register_prompt_error";
		return false;
	}else if(userName1.length<6){
		document.getElementById("password_span").innerHTML="密码不能小于6位!";
		document.getElementById("password_span").className="register_prompt_error";
		return false;
	}
	
	
		document.getElementById("password_span").innerHTML="通过!";
		document.getElementById("password_span").className="register_prompt_ok";
		return true;
	
}
function checkPwd(){
	var userName1=document.getElementById("password").value;
	var userName2=document.getElementById("password2").value;
	if(userName2==""){
		document.getElementById("password2_span").innerHTML="密码不能为空!";
		document.getElementById("password2_span").className="register_prompt_error";
		return false;
	}
	else if(userName2!=userName1){
		document.getElementById("password2_span").innerHTML="两次密码不一致!";
		document.getElementById("password2_span").className="register_prompt_error";
		return false;
	}
		document.getElementById("password2_span").innerHTML="通过!";
		document.getElementById("password2_span").className="register_prompt_ok";
		return true;
	
}
function cksel(){
	if($("#selectClassName").val()==0){
			document.getElementById("reg_yzm_span").innerHTML="请选择班级!";
			document.getElementById("reg_yzm_span").className="register_prompt_error";
			return false;
	}
		document.getElementById("reg_yzm_span").innerHTML="通过!";
		document.getElementById("reg_yzm_span").className="register_prompt_ok";
		return true;
}

function ck(){
	var result=false;
	if(checkUserName()==checkUserName){return result}
	else if(cksel()==result){return result}
	else if(checkNickName()==result){return result}
	else if(checkPwd1()==result){return result}
	else if(checkPwd()==result){return result}
	else{return true};	
}
window.onload=function(){
	
	document.forms["myform"].onsubmit=function(){
		var result=true;
		result=ck();
		if(result){
			return true;
		}
		return false;
		
	}
	
}




